package tests;


import java.util.ArrayList;
import java.util.List;


import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import command.*;
import condition.*;

import roborally.Compiler;
import roborally.Direction;
import roborally.EnergyAmount;
import roborally.EnergyUnit;
import roborally.Position;


/**
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 * 
 */
public class CompilerTest {
	
	/**
	 * Set up an immutable test fixture.
	 * @post   The robot defaultRobot references a new
	 *         robot with position (0,0), energy 0 and orientation 0.
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		
	}
	
	/**
	 * Set up a mutable test fixture.
	 * 
	 * @post   The variable robot33Orient0Energy20000 references a new
	 *         robot with with position (3,3), energy 20000 and orientation 0.
	 * @post   The variable robot82Orient3Energy8000 references a new
	 *         robot with  position (8,2), energy 8000 and orientation 3.
	 */
	@Before
	public void setUp() throws Exception {
		
	}
	
	@Test
	public void compile(){
		assertEquals(new Shoot(), Compiler.compile("(shoot)"));
		List<Command> list = new ArrayList<>();
		list.add(new Move());
		list.add(new Turn(Direction.CLOCKWISE));
		assertEquals(new While(new WallCondition(), new Sequence(list)), Compiler.compile("(while (wall) (seq (move)(turn clockwise)))"));
		assertEquals(new If(new And(new EnergyAtLeast(new EnergyAmount(500,EnergyUnit.WATTSECONDS)), new CanHitRobot()), new PickupAndUse(), new Move()), Compiler.compile("(if(and (energy-at-least 500) (can-hit-robot)) (pickup-and-use) (move))"));
		assertEquals(new Or(new AtItem(), new True()), Compiler.compile("(or(at-item)(true))"));
		assertEquals(new Turn(Direction.COUNTERCLOCKWISE), Compiler.compile("(turn counterclockwise)"));
		assertEquals(new SubRange(new Position(35,625), new Position(40,789)), Compiler.compile("(between (35,625) (40,789) )"));
	}
	
	@Test
	public void compile2(){
		List<Command> list = new ArrayList<>();
		List<Command> list1 = new ArrayList<>();
		list1.add(new Shoot());
		list1.add(new PickupAndUse());
		list1.add(new Turn(Direction.CLOCKWISE));
		list.add(new If(new Not(new WallCondition()), new Sequence(list1), new Shoot()));
		list.add(new While(new And(new CanHitRobot(), new True()), new Turn(Direction.COUNTERCLOCKWISE)));
		list.add(new If(new Or(new EnergyAtLeast(new EnergyAmount(200, EnergyUnit.WATTSECONDS)), new AtItem()), new Move(), new Turn(Direction.CLOCKWISE)));
		assertEquals(new Sequence(list), Compiler.compile("(seq (if(not (wall)) (seq (shoot)	 (pickup-and-use) (turn clockwise)) (shoot)) (while (and(can-hit-robot)(true)) (turn counterclockwise))(if( or (energy-at-least 200) (at-item)) (move) (turn clockwise)))"));
	}

}

